package yxk.task;

import kd.bos.context.RequestContext;
import kd.bos.exception.KDException;
import kd.bos.logging.Log;
import kd.bos.logging.LogFactory;
import kd.bos.openapi.common.result.CustomApiResult;
import kd.bos.schedule.executor.AbstractTask;
import kd.sdk.plugin.Plugin;
import kd.wtc.wtis.webapi.punchcard.PunchCardApi;
import kd.wtc.wtis.webapi.punchcard.model.PunchCardReqMode;
import kd.wtc.wtis.webapi.punchcard.model.PunchCardRespModel;
import kd.wtc.wtis.webapi.punchcard.validate.ListValidator;
import yxk.task.utils.PunchcardDataUtil;
import yxk.utils.DateUtil;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author lijiawang
 * @Date 2023/9/12 14:27
 * @Description:获取飞书的打卡记录;
 */
public class PunchcardDataTask extends AbstractTask implements Plugin {
    private static final Log LOG = LogFactory.getLog(PunchcardDataTask.class);
    @Override
    public void execute(RequestContext requestContext, Map<String, Object> map) throws KDException {
        PunchcardDataUtil punchcardDataUtil=new PunchcardDataUtil();
        PunchCardApi api=new PunchCardApi();
        SimpleDateFormat format=new SimpleDateFormat("yyyyMMdd");
        //获取前一天的日期
        Date day = DateUtil.MonthAdd(new Date(), Calendar.DATE, -1);
        String date = format.format(day);
        String endDate = format.format(new Date());
        List<ListValidator<PunchCardReqMode>> list = punchcardDataUtil.getFSPunchcardObtainList(date,endDate);
        //每一千条数据
        for (ListValidator<PunchCardReqMode> punchCardReqModes : list) {
            CustomApiResult<PunchCardRespModel> punchCardRespModel = api.syncCardRecordService(punchCardReqModes);
            LOG.info("PunchcardDataTask.execute.punchCardRespModel:{}",punchCardRespModel);
        }



    }
}